<template>
    <!-- 添加或修改采购单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="产品id" prop="goodsId">
                                <el-input v-model="form.goodsId" placeholder="请输入产品id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产品名称" prop="goodsName">
                                <el-input v-model="form.goodsName" placeholder="请输入产品名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产品规格明细" prop="goodsBrand">
                                <el-input v-model="form.goodsBrand" placeholder="请输入产品规格明细"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产品型号" prop="goodModel">
                                <el-input v-model="form.goodModel" placeholder="请输入产品型号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售单价" prop="goodsUnitPrice">
                                <el-input v-model="form.goodsUnitPrice" placeholder="请输入销售单价"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售数量" prop="goodsCount">
                                <el-input v-model="form.goodsCount" placeholder="请输入销售数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="总价" prop="goodsTotalPrice">
                                <el-input v-model="form.goodsTotalPrice" placeholder="请输入总价"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="成本单价" prop="goodsBuyPrice">
                                <el-input v-model="form.goodsBuyPrice" placeholder="请输入成本单价"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="成本金额" prop="goodsBuyTotal">
                                <el-input v-model="form.goodsBuyTotal" placeholder="请输入成本金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售利润" prop="goodsProfit">
                                <el-input v-model="form.goodsProfit" placeholder="请输入销售利润"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售日期" prop="saleDate">
                                <el-date-picker clearable
                                                v-model="form.saleDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择销售日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="供应商" prop="supplierId">
                                <el-input v-model="form.supplierId" placeholder="请输入供应商"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="供应商名称" prop="supplierName">
                                <el-input v-model="form.supplierName" placeholder="请输入供应商名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="客户" prop="customerId">
                                <el-input v-model="form.customerId" placeholder="请输入客户"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="客户名称" prop="customerName">
                                <el-input v-model="form.customerName" placeholder="请输入客户名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售人" prop="saleId">
                                <el-input v-model="form.saleId" placeholder="请输入销售人"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="销售人姓名" prop="saleName">
                                <el-input v-model="form.saleName" placeholder="请输入销售人姓名"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="删除标志" prop="delFlag">
                                <el-input v-model="form.delFlag" placeholder="请输入删除标志"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="备注" prop="remark">
                                <el-input v-model="form.remark" placeholder="请输入备注"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="订单编号" prop="projectId">
                                <el-input v-model="form.projectId" placeholder="请输入订单编号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="订单名称" prop="projectName">
                                <el-input v-model="form.projectName" placeholder="请输入订单名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="部门ID" prop="deptId">
                                <el-input v-model="form.deptId" placeholder="请输入部门ID"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="部门名称" prop="deptName">
                                <el-input v-model="form.deptName" placeholder="请输入部门名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="请购数量" prop="counts">
                                <el-input v-model="form.counts" placeholder="请输入请购数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="剩余数量" prop="shengyu">
                                <el-input v-model="form.shengyu" placeholder="请输入剩余数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否发货" prop="isfahuo">
                                <el-input v-model="form.isfahuo" placeholder="请输入是否发货"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="发货时间" prop="fahuoDate">
                                <el-date-picker clearable
                                                v-model="form.fahuoDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择发货时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产品编码" prop="code">
                                <el-input v-model="form.code" placeholder="请输入产品编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="吨位" prop="dun">
                                <el-input v-model="form.dun" placeholder="请输入吨位"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="单据号" prop="nos">
                                <el-input v-model="form.nos" placeholder="请输入单据号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="是否自制(1:自制; 2:请购; 3:外协)" prop="isdo">
                                <el-input v-model="form.isdo" placeholder="请输入是否自制(1:自制; 2:请购; 3:外协)"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="采购单id" prop="mainId">
                                <el-input v-model="form.mainId" placeholder="请输入采购单id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="请购单id" prop="qinggouId">
                                <el-input v-model="form.qinggouId" placeholder="请输入请购单id"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "GoodsSalebuyForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/goodsSalebuy/goodsSalebuy/',
                    add:'/goodsSalebuy/goodsSalebuy/add',
                    edit:'/goodsSalebuy/goodsSalebuy/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
            id: null,
            type: null,
            goodsId: null,
            goodsName: null,
            goodsBrand: null,
            goodModel: null,
            goodsUnitPrice: null,
            goodsCount: null,
            goodsTotalPrice: null,
            goodsBuyPrice: null,
            goodsBuyTotal: null,
            goodsProfit: null,
            saleDate: null,
            supplierId: null,
            supplierName: null,
            customerId: null,
            customerName: null,
            saleId: null,
            saleName: null,
            delFlag: null,
            createBy: null,
            createTime: null,
            updateBy: null,
            updateTime: null,
            remark: null,
            projectId: null,
            projectName: null,
        status: "0",
            deptId: null,
            deptName: null,
            counts: null,
            shengyu: null,
            isfahuo: null,
            fahuoDate: null,
            code: null,
            dun: null,
            nos: null,
            isdo: null,
            mainId: null,
            qinggouId: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加采购单";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改采购单";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
